/*     */ package dm.jdbc.util;
/*     */ 
/*     */ public class IPAddressUtil {
/*     */   private static final int INADDR4SZ = 4;
/*     */   private static final int INADDR16SZ = 16;
/*     */   private static final int INT16SZ = 2;
/*     */   
/*     */   public static byte[] textToNumericFormatV4(String paramString) {
/*   9 */     if (paramString.length() == 0)
/*  10 */       return null;
/*  11 */     byte[] arrayOfByte = new byte[4];
/*  12 */     String[] arrayOfString = paramString.split("\\.", -1);
/*     */     
/*     */     try
/*     */     {
/*  16 */       switch (arrayOfString.length) {
/*     */       case 1: 
/*  18 */         long l = Long.parseLong(arrayOfString[0]);
/*  19 */         if ((l < 0L) || (l > 4294967295L))
/*  20 */           return null;
/*  21 */         arrayOfByte[0] = ((byte)(int)(l >> 24 & 0xFF));
/*  22 */         arrayOfByte[1] = ((byte)(int)((l & 0xFFFFFF) >> 16 & 0xFF));
/*  23 */         arrayOfByte[2] = ((byte)(int)((l & 0xFFFF) >> 8 & 0xFF));
/*  24 */         arrayOfByte[3] = ((byte)(int)(l & 0xFF));
/*  25 */         break;
/*     */       case 2: 
/*  27 */         long l = Integer.parseInt(arrayOfString[0]);
/*  28 */         if ((l < 0L) || (l > 255L))
/*  29 */           return null;
/*  30 */         arrayOfByte[0] = ((byte)(int)(l & 0xFF));
/*  31 */         l = Integer.parseInt(arrayOfString[1]);
/*  32 */         if ((l < 0L) || (l > 16777215L))
/*  33 */           return null;
/*  34 */         arrayOfByte[1] = ((byte)(int)(l >> 16 & 0xFF));
/*  35 */         arrayOfByte[2] = ((byte)(int)((l & 0xFFFF) >> 8 & 0xFF));
/*  36 */         arrayOfByte[3] = ((byte)(int)(l & 0xFF));
/*  37 */         break;
/*     */       case 3: 
/*  39 */         for (int i = 0; i < 2; i++) {
/*  40 */           long l = Integer.parseInt(arrayOfString[i]);
/*  41 */           if ((l < 0L) || (l > 255L))
/*  42 */             return null;
/*  43 */           arrayOfByte[i] = ((byte)(int)(l & 0xFF));
/*     */         }
/*  45 */         long l = Integer.parseInt(arrayOfString[2]);
/*  46 */         if ((l < 0L) || (l > 65535L))
/*  47 */           return null;
/*  48 */         arrayOfByte[2] = ((byte)(int)(l >> 8 & 0xFF));
/*  49 */         arrayOfByte[3] = ((byte)(int)(l & 0xFF));
/*  50 */         break;
/*     */       case 4: 
/*  52 */         for (int i = 0; i < 4; i++) {
/*  53 */           long l = Integer.parseInt(arrayOfString[i]);
/*  54 */           if ((l < 0L) || (l > 255L))
/*  55 */             return null;
/*  56 */           arrayOfByte[i] = ((byte)(int)(l & 0xFF));
/*     */         }
/*  58 */         break;
/*     */       default: 
/*  60 */         return null;
/*     */       }
/*     */     } catch (NumberFormatException localNumberFormatException) {
/*  63 */       return null;
/*     */     }
/*  65 */     return arrayOfByte;
/*     */   }
/*     */   
/*     */   public static byte[] textToNumericFormatV6(String paramString) {
/*  69 */     if (paramString.length() < 2)
/*  70 */       return null;
/*  71 */     char[] arrayOfChar = paramString.toCharArray();
/*  72 */     byte[] arrayOfByte1 = new byte[16];
/*  73 */     int m = arrayOfChar.length;
/*  74 */     int n = paramString.indexOf("%");
/*  75 */     if (n == m - 1)
/*  76 */       return null;
/*  77 */     if (n != -1)
/*  78 */       m = n;
/*  79 */     int i = -1;
/*  80 */     int i1 = 0;
/*  81 */     int i2 = 0;
/*  82 */     if (arrayOfChar[i1] == ':') {
/*  83 */       i1++;
/*  84 */       if (arrayOfChar[i1] != ':')
/*  85 */         return null;
/*     */     }
/*  87 */     int i3 = i1;
/*  88 */     int j = 0;
/*  89 */     int k = 0;
/*     */     
/*  91 */     while (i1 < m) {
/*  92 */       char c = arrayOfChar[(i1++)];
/*  93 */       int i4 = Character.digit(c, 16);
/*  94 */       if (i4 != -1) {
/*  95 */         k <<= 4;
/*  96 */         k |= i4;
/*  97 */         if (k > 65535)
/*  98 */           return null;
/*  99 */         j = 1;
/*     */ 
/*     */       }
/* 102 */       else if (c == ':') {
/* 103 */         i3 = i1;
/* 104 */         if (j == 0) {
/* 105 */           if (i != -1)
/* 106 */             return null;
/* 107 */           i = i2;
/*     */         }
/*     */         else {
/* 110 */           if (i1 == m)
/* 111 */             return null;
/* 112 */           if (i2 + 2 > 16)
/* 113 */             return null;
/* 114 */           arrayOfByte1[(i2++)] = ((byte)(k >> 8 & 0xFF));
/* 115 */           arrayOfByte1[(i2++)] = ((byte)(k & 0xFF));
/* 116 */           j = 0;
/* 117 */           k = 0;
/*     */         }
/*     */       }
/* 120 */       else if ((c == '.') && (i2 + 4 <= 16)) {
/* 121 */         String str = paramString.substring(i3, m);
/* 122 */         int i5 = 0;
/* 123 */         for (int i6 = 0; (i6 = str.indexOf('.', i6)) != -1; i6++)
/* 124 */           i5++;
/* 125 */         if (i5 != 3)
/* 126 */           return null;
/* 127 */         byte[] arrayOfByte3 = textToNumericFormatV4(str);
/* 128 */         if (arrayOfByte3 == null)
/* 129 */           return null;
/* 130 */         for (int i7 = 0; i7 < 4; i7++)
/* 131 */           arrayOfByte1[(i2++)] = arrayOfByte3[i7];
/* 132 */         j = 0;
/*     */       } else {
/* 134 */         return null;
/*     */       }
/*     */     }
/* 137 */     if (j != 0) {
/* 138 */       if (i2 + 2 > 16)
/* 139 */         return null;
/* 140 */       arrayOfByte1[(i2++)] = ((byte)(k >> 8 & 0xFF));
/* 141 */       arrayOfByte1[(i2++)] = ((byte)(k & 0xFF));
/*     */     }
/* 143 */     if (i != -1) {
/* 144 */       int i4 = i2 - i;
/* 145 */       if (i2 == 16)
/* 146 */         return null;
/* 147 */       for (i1 = 1; i1 <= i4; i1++) {
/* 148 */         arrayOfByte1[(16 - i1)] = arrayOfByte1[(i + i4 - i1)];
/* 149 */         arrayOfByte1[(i + i4 - i1)] = 0;
/*     */       }
/* 151 */       i2 = 16;
/*     */     }
/* 153 */     if (i2 != 16)
/* 154 */       return null;
/* 155 */     byte[] arrayOfByte2 = convertFromIPv4MappedAddress(arrayOfByte1);
/* 156 */     if (arrayOfByte2 != null)
/* 157 */       return arrayOfByte2;
/* 158 */     return arrayOfByte1;
/*     */   }
/*     */   
/*     */   public static boolean isIPv4LiteralAddress(String paramString) {
/* 162 */     return textToNumericFormatV4(paramString) != null;
/*     */   }
/*     */   
/*     */   public static boolean isIPv6LiteralAddress(String paramString) {
/* 166 */     return textToNumericFormatV6(paramString) != null;
/*     */   }
/*     */   
/*     */   public static byte[] convertFromIPv4MappedAddress(byte[] paramArrayOfByte) {
/* 170 */     if (isIPv4MappedAddress(paramArrayOfByte)) {
/* 171 */       byte[] arrayOfByte = new byte[4];
/* 172 */       System.arraycopy(paramArrayOfByte, 12, arrayOfByte, 0, 4);
/* 173 */       return arrayOfByte;
/*     */     }
/* 175 */     return null;
/*     */   }
/*     */   
/*     */   private static boolean isIPv4MappedAddress(byte[] paramArrayOfByte) {
/* 179 */     if (paramArrayOfByte.length < 16)
/* 180 */       return false;
/* 181 */     return (paramArrayOfByte[0] == 0) && (paramArrayOfByte[1] == 0) && 
/* 182 */       (paramArrayOfByte[2] == 0) && (paramArrayOfByte[3] == 0) && 
/* 183 */       (paramArrayOfByte[4] == 0) && (paramArrayOfByte[5] == 0) && 
/* 184 */       (paramArrayOfByte[6] == 0) && (paramArrayOfByte[7] == 0) && 
/* 185 */       (paramArrayOfByte[8] == 0) && (paramArrayOfByte[9] == 0) && 
/* 186 */       (paramArrayOfByte[10] == -1) && (paramArrayOfByte[11] == -1);
/*     */   }
/*     */ }


/* Location:              D:\Program Files\DBMS_20150813\jdbc\Dm7JdbcDriver17.jar!\dm\jdbc\util\IPAddressUtil.class
 * Java compiler version: 2 (46.0)
 * JD-Core Version:       0.7.1
 */